<template>
	<view class="container">
		<uni-card title="获取抖音POI" v-show="activestep == 1">
			<u--form labelPosition="left" :model="formData" ref="POIForm" :label-width="80" :rules="POIrules">
				<u-form-item label="链接URL:" prop="url" ref="item1" required>
					<u--input v-model="formData.url" placeholder="请输入内容"></u--input>
				</u-form-item>
				<view style="display: flex;justify-content: space-around;align-items: center;">
					<button type="primary" size="mini" @click="getjinwei()">获取</button>
					<uni-icons type="help" size="23" color="red"></uni-icons>
					<span @click="linkWay" style="margin-bottom: 8rpx;">链接获取方式</span>
				</view>
				<u-form-item label="抖音POI ID:" prop="dy_poi_id" ref="item1" required>
					<u--input v-model="formData.dy_poi_id" placeholder="请输入内容"></u--input>
				</u-form-item>
				<u-form-item>
					<u-button type="success" text="获取详细地址和经纬度" @click="getMapAddress"></u-button>
				</u-form-item>
				<u-form-item label="详细地址:" prop="douObj.address" ref="item1" required>
					<u--input v-model="formData.douObj.address" placeholder="请输入内容"></u--input>
				</u-form-item>
				<u-form-item label="经度:" prop="douObj.longitude" ref="item1" required>
					<u--input v-model="formData.douObj.longitude" placeholder="请输入内容"></u--input>
				</u-form-item>
				<u-form-item label="纬度:" prop="douObj.latitude" ref="item1" required>
					<u--input v-model="formData.douObj.latitude" placeholder="请输入内容"></u--input>
				</u-form-item>
			</u--form>
		</uni-card>
		<u-popup :show="linkShow" @close="linkShow=false" mode="center" :round="10" closeOnClickOverlay>
			<view style="width: 80vw;margin: 0 auto;padding: 10rpx;20rpx">
				<view style="font-size: 19px;font-weight: 600;color: #000;margin-top: 20rpx;">地址链接获取流程:</view>
				<view class="linkPopup">1.打开手机浏览器搜索高德地图(注意高德地图app不支持)</view>
				<view class="linkPopup">2.搜索商家名称，选取正确的商家地址后，点击如下图位置的商家名称</view>
				<view style="display: flex;align-items: center;justify-content: space-around;margin-top: 20rpx;">
					<u--image :src="personPicUrl" width="100px" height="200px"
						@click="imgPreview(personPicUrl)"></u--image>
					<u--image :src="personPicUrl2" width="100px" height="200px"
						@click="imgPreview2(personPicUrl2)"></u--image>
				</view>
				<view class="linkPopup">3.点击名称后，复制网页链接并粘贴至上方文本框并保存即可</view>
				<view class="linkPopup">正确网页链接格式示例:</view>
				<view class="linkPopup" style=" word-break: break-all;">https://m.amap.com/detail/index/poiid=B0FFKW03NS
				</view>
				<view class="linkPopup" style="font-size: 23rpx;color: red;">说明:正确链接后缀为:poiid=字符串</view>
			</view>
		</u-popup>
		<uni-card title="基本信息" v-show="activestep == 0">
			<uni-forms ref="form" :modelValue="formData" :labelWidth="90">
				<uni-forms-item label="品牌名称">
					<u--input placeholder="请输入内容" border="surround" v-model="formData.chain_name"></u--input>
				</uni-forms-item>
				<uni-forms-item label="门店名称" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.store_name"></u--input>
				</uni-forms-item>
				<uni-forms-item label="抖音POI ID" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.dy_poi_id"></u--input>
				</uni-forms-item>
				<uni-forms-item label="手机号" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.phone"></u--input>
				</uni-forms-item>
				<!-- <uni-forms-item label="营业状态" :label-width="90">
						<uni-data-checkbox v-model="formData.dy_status" :localdata="dy_status"
							@change="statusChange"></uni-data-checkbox>
					</uni-forms-item> -->
				<uni-forms-item label="接单状态" v-if="menus.includes('store/diandan')">
					<uni-data-checkbox v-model="formData.place_status" :localdata="place_status"
						@change="placeChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="门店分类" v-if="adminInfo.store_id == 0">
					<uni-data-checkbox v-model="formData.is_chain" :localdata="is_chain"
						@change="chainChange"></uni-data-checkbox>
				</uni-forms-item>
				<!-- <uni-forms-item label="分佣比例" v-if="menus.includes('store/store/cybl') && adminInfo.store_id == 0">
					<u-number-box v-model="formData.commission_ratio" :decimal-length="2" :step="0.01" longPress
						inputWidth="40" :min="0" :max="30"></u-number-box>
					<span class="ml10">(百分比/15%)</span>
				</uni-forms-item> -->
			</uni-forms>
		</uni-card>
		<uni-card title="配送信息" v-show="activestep == 2">
			<uni-forms ref="form" :label-position="alignment" :modelValue="formData">
				<uni-forms-item label="营业时间" required>
					<view
						style="height: 80rpx;display: flex;align-items: center;background-color: #f7f7f7;padding: 18rpx;border-radius: 10rpx;">
						<xp-picker v-model="formData.open_time[0][0]" mode="his" @confirm="timeChoose1" />
						<span style="margin-left: 25rpx;">至</span>
						<xp-picker v-model="formData.open_time[0][1]" mode="his" @confirm="timeChoose2" />
					</view>
					<button size="mini" style="background-color: #ffffff;" @click="isShow = true"
						v-if="isShow == false">
						<uni-icons type="plus-filled" size="24"></uni-icons>
					</button>
					<view v-if="isShow"
						style="height: 80rpx;display: flex;align-items: center;background-color: #f7f7f7;padding: 18rpx;border-radius: 10rpx;margin-top: 10rpx;">
						<xp-picker v-model="formData.open_time[1][0]" mode="his" @confirm="timeChoose3" />
						<span style="margin-left: 25rpx;">至</span>
						<xp-picker v-model="formData.open_time[1][1]" mode="his" @confirm="timeChoose4" />
					</view>
					<button size="mini" style="background-color: #ffffff;" @click="isShow = false"
						v-if="isShow == true">
						<uni-icons type="trash-filled" size="24"></uni-icons>
					</button>
				</uni-forms-item>
				<uni-forms-item label="预约时长">
					<view class="text">需提前</view>
					<u-number-box v-model="formData.appointment_duration" @change="valChange"></u-number-box>
					<view class="text">分钟</view>
				</uni-forms-item>
				<uni-forms-item label="时段细分">
					<uni-data-checkbox v-model="formData.time_period_segmentation" :localdata="timeList"
						@change="groupChangeTime"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="最长预约">
					<view class="text">可预约</view>
					<u-number-box v-model="formData.longest_appointment" @change="longestChange"></u-number-box>
					<view class="text">天内订单</view>
				</uni-forms-item>
				<uni-forms-item label="营业日期" required>
					<uni-data-checkbox multiple v-model="formData.open_date" :localdata="dateList"
						@change="checkboxClick"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="起送价">
					<u--input placeholder="请输入内容" border="surround" type="digit"
						v-model="formData.starting_price"></u--input>
				</uni-forms-item>
				<uni-forms-item label="点单预计取货时间(分钟)" label-width="200">
					<u--input placeholder="请输入内容" border="surround" type="digit"
						v-model="formData.place_time"></u--input>
				</uni-forms-item>
				<uni-forms-item label="配送规则">
					<view style="display: flex;justify-content: space-around;flex-wrap: wrap;align-items: center;">
						<span>配送路线距离</span><u-number-box v-model="formData.delivery_scope" :step="0.1"></u-number-box>
						<span>公里，</span>
						<span>为0或者不填写表示不限制路线距离<span style="color: red">（配送路线以高德官方计算为准）</span></span>
					</view>
				</uni-forms-item>
				<uni-forms-item>
					<view v-for="(item, i) in formData.distance_price" :key="i"
						style="display: flex;justify-content: space-around;flex-wrap: wrap;align-items: center;">
						<span v-if="i == 0">多少</span>
						<span v-if="i != 0">{{ formData.distance_price[i - 1].gong }}至</span>
						<u-number-box v-model="item.gong" :min="i != 0 ? formData.distance_price[i - 1].gong + 1 : 0" />
						<span>公里内，</span>
						<span v-if="i == 0">起步价</span>
						<span v-if="i != 0">每多</span>
						<u-number-box v-if="i != 0" v-model="item.duo" :min="0" :step="0.1" />
						<span v-if="i != 0">公里加收</span>
						<u-number-box v-model="item.price" :min="0" :step="0.1" />
						<span>元。</span>
						<button @click="additem(i)" size="mini" style="background-color: #ffffff;">
							<uni-icons type="plus-filled" size="24"></uni-icons>
						</button>
						<button v-if="i != 0" @click="deleteitem(i)" size="mini" style="background-color: #ffffff;">
							<uni-icons type="trash-filled" size="24"></uni-icons>
						</button>
					</view>
				</uni-forms-item>
				<uni-forms-item label="配送时长">
					<view style="display: flex;justify-content: space-between;flex-wrap: wrap;align-items: center;">
						<span></span><u-number-box :step="0.1" v-model="formData.starting_distance" :min="0"
							controls-position="right" />
						<span>公里内，</span>
						<span>配送时长</span><u-number-box :step="1" v-model="formData.starting_time" :min="0"
							controls-position="right" />
						<span>分钟，每增加1公里，配送时长增加</span>
						<u-number-box v-model="formData.stage_duration" :step="1" :min="0"
							controls-position="right" />分钟
					</view>
				</uni-forms-item>
				<u-divider></u-divider>
				<uni-forms-item label="商家额外承担的配送费：" label-width="300">
					<u-number-box v-model="formData.delivery_minus_fee" :min="0"></u-number-box>
				</uni-forms-item>
				<u-divider></u-divider>
				<uni-forms-item label="满免配送费是否开启：" label-width="300">
					<uni-data-checkbox v-model="formData.is_delivery_minus"
						:localdata="manjianList"></uni-data-checkbox>
				</uni-forms-item>
				<u-divider></u-divider>
				<uni-forms-item label="满免配送费配置：" label-width="300" v-if="formData.is_delivery_minus == 1">
					<view class="">
						<view class="" style="width: 100%;">
							<u-button text="添加" @click="addManitem()" type="success"></u-button>
						</view>
						<div v-for="(item, i) in formData.delivery_minus_data" :key="i" style="margin-top: 20rpx;">
							<view class="" style="display: flex;align-items: center;">
								<view>订单距离</view>
							<!-- 	<u-number-box v-model="item.distance"
									:min="i != 0 ? formData.delivery_minus_data[i - 1].distance + 1 : 0"
									:max="formData.delivery_scope"></u-number-box> -->
									<u--input
									    border="surround"
									    v-model="item.distance"
									    @change="change"
										type="digit"
									  ></u--input>
								<view>公里内</view>
							</view>

							<view class="" style="display: flex;align-items: center;margin-top: 10rpx;">
								<view>满</view>
								<!-- <u-number-box v-model="item.fee"
									:min="i != 0 ? (Number(formData.delivery_minus_data[i - 1].fee) + 1) : 0"></u-number-box> -->
									<u--input
									    border="surround"
									     v-model="item.fee"
									    @change="change"
										type="digit"
									  ></u--input>
								<view>元免配送费</view>
								<button style="width: 180rpx;height: 60rpx;font-size: 26rpx;" @click="removeManitem(i)"
									v-if="i > 0" type="warn">删除</button>
							</view>
							<u-divider></u-divider>
						</div>
					</view>
				</uni-forms-item>
				<uni-forms-item label="配送费归属上级：" label-width="300" v-if="adminInfo.oem_id==0">
					<uni-data-checkbox v-model="formData.is_delivery_price_higher"
						:localdata="is_delivery_price_higher"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="配送费归属上级：" label-width="300"
					v-if="formData.is_delivery_price_higher==1 && adminInfo.oem_id==0">
					<uni-data-checkbox v-model="formData.delivery_price_higher_type"
						:localdata="delivery_price_higher_type"></uni-data-checkbox>
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="其他信息" v-show="activestep == 0">
			<uni-forms ref="form" :labelWidth="90">
				<uni-forms-item label="选择地区">
					<view class="area" @click="openPicker">
						{{formData.province}}/{{formData.city}}/{{formData.county}}
					</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="logo图片">
						<u-upload :fileList="formData.logo_img" @afterRead="afterRead" @delete="deletePic"
							uploadIcon="plus" name="1" :maxCount="3" multiple></u-upload>
					</uni-forms-item>
					<uni-forms-item label="店铺图片">
						<u-upload :fileList="formData.store_img" @afterRead="afterRead" @delete="deletePic"
							uploadIcon="plus" name="2" :maxCount="3" multiple></u-upload>
					</uni-forms-item> -->
				<uni-forms-item label="资质图片" v-if="formData.is_chain == 0">
					<u-upload :fileList="formData.qualifications" @afterRead="afterRead" @delete="deletePic"
						uploadIcon="plus" name="3" :maxCount="3" multiple></u-upload>
				</uni-forms-item>
				<uni-forms-item label="食品经营许可证" v-if="formData.is_chain == 0">
					<u-upload :fileList="formData.business_license" @afterRead="afterRead" @delete="deletePic"
						uploadIcon="plus" name="4" :maxCount="3" multiple></u-upload>
				</uni-forms-item>
				<uni-forms-item label="详细地址" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.address"></u--input>
				</uni-forms-item>
				<uni-forms-item label="经度">
					<u--input placeholder="请输入内容" border="surround" v-model="formData.lng"></u--input>
				</uni-forms-item>
				<uni-forms-item label="纬度">
					<u--input placeholder="请输入内容" border="surround" v-model="formData.lat"></u--input>
				</uni-forms-item>
				<!-- <uni-forms-item label="店铺介绍">
						<textarea class="textarea" placeholder="请输入内容" v-model="formData.description"></textarea>
					</uni-forms-item> -->
			</uni-forms>
		</uni-card>
		<view class="footer">
			<u-button type="primary" text="取消" :plain="true" @click="cancel"
				v-if="activestep == 0 || activestep == 2"></u-button>
			<u-button type="success" text="下一步" @click="next(1)" v-if="activestep == 1"></u-button>
			<u-button type="success" text="上一步" @click="next(0)" v-if="activestep == 0 && editorsave == 2"></u-button>
			<u-button type="primary" text="确定" @click="submit()" v-if="activestep == 0 || activestep == 2"></u-button>
		</view>
		<view class="null"></view>
		<cc-selectDity :province="province" :city="city" :area="area" :show="show" @changeClick="changeClick"
			@sureSelectArea="onsetCity" @hideShow="onhideShow"></cc-selectDity>
	</view>
</template>

<script>
	import config from '@/custom/config.js';
	import site from '@/custom/siteroot.js';
	import COS from 'cos-wx-sdk-v5';
	import CryptoJS from 'crypto-js';
	import {
		mapState,
	} from 'vuex'
	export default {
		data() {
			return {
				cos: null, // COS SDK 实例
				hexList: [],
				editorsave: '',
				isShow: true,
				linkShow: false,
				adminInfo: uni.getStorageSync('adminInfo'),
				formData: {
					store_name: '',
					chain_name: '',
					phone: '',
					url: '',
					province: '',
					city: '',
					county: '',
					commission_ratio: 0,
					address: '',
					is_chain: 0,
					lng: '',
					lat: '',
					poi_id: '',
					dy_poi_id: '',
					merchant_id: '',
					store_img: [],
					logo_img: [],
					qualifications: [],
					business_license: [],
					authorization: [],
					description: '',
					type: 2,
					open_time: [
						[],
						[]
					],
					bus_img: [],
					telephone: '',
					merchant_uid: '',
					tags: '',
					dy_status: 1,
					type_code: '',
					type_name: '',
					avg_cost: 0,
					customer_info: [],
					recommends: [],
					place_time: 30,
					starting_price: 0,
					place_status: 1,
					open_date: ['1', '2', '3', '4', '5', '6', '7'],
					douObj: {
						poi_name: '',
						poi_id: '',
						city: '',
						address: '',
						amap_id: '',
						longitude: '',
						latitude: '',
					},
					delivery_scope: 0,
					distance_price: [{
						gong: 0,
						duo: 0,
						price: 0,
					}, ],
					delivery_minus_fee: '',
					is_delivery_minus: 0,
					delivery_minus_data: [{
						distance: 0,
						fee: 0,
					}],
					is_delivery_price_higher: 0,
					delivery_price_higher_type: 1,
				},
				province: "山东省",
				city: "济南市",
				area: "历下区",
				areaCode: "370102",
				addressData: {
					address: '',
					moreAddres: '',
					isdefult: 0
				},
				show: false,
				alignment: "top",
				dy_status: [{
						text: "上线",
						value: 1
					},
					{
						text: "下线",
						value: 2
					}
				],
				place_status: [{
						text: "接单",
						value: 1
					},
					{
						text: "不接单",
						value: 2
					}
				],
				manjianList: [{
						text: "开启",
						value: 1
					},
					{
						text: "关闭",
						value: 2
					}
				],
				is_delivery_price_higher: [{
						text: "是",
						value: 1
					},
					{
						text: "否",
						value: 0
					}
				],
				delivery_price_higher_type: [{
						text: "OEM",
						value: 1
					},
					{
						text: "代理",
						value: 2
					},
					{
						text: "合伙人",
						value: 3
					}
				],

				is_chain: [{
						text: "单店",
						value: 0,
						disable: false
					},
					{
						text: "连锁",
						value: 1
					}
				],
				timeList: [{
						text: "半小时",
						value: "30"
					},
					{
						text: "1小时",
						value: "60"
					},
					{
						text: "2小时",
						value: "120"
					},
					{
						text: "4小时",
						value: "240"
					},
					{
						text: "6小时",
						value: "360"
					},
					{
						text: "12小时",
						value: "720"
					}
				],
				dateList: [{
						text: '星期一',
						value: 1
					}, {
						text: '星期二',
						value: 2
					}, {
						text: '星期三',
						value: 3
					},
					{
						text: '星期四',
						value: 4
					},
					{
						text: '星期五',
						value: 5
					},
					{
						text: '星期六',
						value: 6
					},
					{
						text: '星期日',
						value: 7
					}
				],
				radiovalueDate: '',
				fileList1: [],
				fileList2: [],
				radiolist1: [{
						name: '酒店民宿',
						type: 1
					},
					{
						name: '餐饮',
						type: 2
					},
					{
						name: '景区',
						type: 3
					}, {
						name: '电商',
						type: 4
					},
					{
						name: '教育',
						type: 5
					},
					{
						name: '丽人',
						type: 6
					},
					{
						name: '爱车',
						type: 7
					},
					{
						name: '亲子',
						type: 8
					},
					{
						name: '宠物',
						type: 9
					},
					{
						name: '家装',
						type: 10
					},
					{
						name: '娱乐场所',
						type: 11
					},
					{
						name: '图文快印',
						type: 12
					},
				],
				activestep: '',
				POIrules: {
					'url': {
						type: 'string',
						required: true,
						message: '请填写链接url',
						trigger: ['blur', 'change']
					},
					'dy_poi_id': {
						type: 'string',
						required: true,
						message: '请填写抖音POI ID',
						trigger: ['blur', 'change']
					},
					// 'douObj.address': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写详细地址',
					// 	trigger: ['blur', 'change']
					// },
					// 'douObj.longitude': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写经度',
					// 	trigger: ['blur', 'change']
					// },
					// 'douObj.latitude': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写纬度',
					// 	trigger: ['blur', 'change']
					// },
				},
				personPicUrl: 'https://douyin-1325951894.cos.ap-beijing.myqcloud.com/storage/default/20241008/LcsFc7A7dhPc278c8997eb4513347b9254790009a874.png',
				personPicUrl2: 'https://douyin-1325951894.cos.ap-beijing.myqcloud.com/storage/default/20241008/rvGicQBRY0SM2f639119168b7e4bb3ec85678799fe0e.png',
			}
		},
		onReady() {
			this.$refs.POIForm.setRules(this.POIrules)
		},
		computed: {
			...mapState({
				menus: state => state.menus,
			}),
		},
		onLoad(option) {
			this.editorsave = option.type
			if (option.type == 1) {
				this.activestep = 0
				this.formData = JSON.parse(decodeURIComponent(option.item))
				this.formData.delivery_minus_data = [{
						distance: 0,
						fee: 0,
					}],
				console.log(this.formData)
				// if (this.formData.logo_img.length > 0) {
				// 	let arr = [];
				// 	this.formData.logo_img.forEach((v) => {
				// 		arr.push({
				// 			url: 'https://douyin-1325951894.cos.ap-beijing.myqcloud.com' + v,
				// 			src: v
				// 		});
				// 	})
				// 	this.formData.logo_img = arr;
				// }
				// if (this.formData.store_img.length > 0) {
				// 	let arr = [];
				// 	this.formData.store_img.forEach((v) => {
				// 		arr.push({
				// 			url: 'https://douyin-1325951894.cos.ap-beijing.myqcloud.com' + v,
				// 			src: v
				// 		});
				// 	})
				// 	this.formData.store_img = arr;
				// }
				if (this.formData.qualifications.length > 0) {
					let arr = [];
					this.formData.qualifications.forEach((v) => {
						arr.push({
							url: site.siteimgroot + v,
							src: v
						});
					})
					this.formData.qualifications = arr;
				}
				if (this.formData.business_license.length > 0) {
					let arr = [];
					this.formData.business_license.forEach((v) => {
						arr.push({
							url: site.siteimgroot + v,
							src: v
						});
					})
					this.formData.business_license = arr;
				}
				for (let i = 0; i <= 15; i++) {
					this.hexList[i] = i.toString(16)
				}
			} else if (option.type == 2) {
				if (this.formData.qualifications.length > 0) {
					let arr = [];
					this.formData.qualifications.forEach((v) => {
						arr.push({
							url: site.siteimgroot + v,
							src: v
						});
					})
					this.formData.qualifications = arr;
				}
				if (this.formData.business_license.length > 0) {
					let arr = [];
					this.formData.business_license.forEach((v) => {
						arr.push({
							url: site.siteimgroot + v,
							src: v
						});
					})
					this.formData.business_license = arr;
				}
				for (let i = 0; i <= 15; i++) {
					this.hexList[i] = i.toString(16)
				}
				this.activestep = 1
			} else if (option.type == 3) {
				this.formData = JSON.parse(decodeURIComponent(option.item))
				console.log(this.formData)
				if (this.formData.length > 0) {
					if (this.formData.open_time[0][0].length == 19) {
						this.formData.open_time[0][0] = this.formData.open_time[0][0].slice(-8)
						this.formData.open_time[0][1] = this.formData.open_time[0][1].slice(-8)
						this.formData.open_time[1][0] = this.formData.open_time[1][0].slice(-8)
						this.formData.open_time[1][1] = this.formData.open_time[1][1].slice(-8)
					} else {
						this.formData.open_time[0][0] = this.getTimeFromISOString(this.formData.open_time[0][0]);
						this.formData.open_time[0][1] = this.getTimeFromISOString(this.formData.open_time[0][1]);
						this.formData.open_time[1][0] = this.getTimeFromISOString(this.formData.open_time[1][0]);
						this.formData.open_time[1][1] = this.getTimeFromISOString(this.formData.open_time[1][1]);
					}
				}
				if (this.formData.distance_price == '' || this.formData.distance_price == null || this.formData
					.distance_price == 0) {
					this.formData.distance_price = [{
						gong: 0,
						duo: 0,
						price: 0,
					}, ]
				}
				this.formData.distance_price.forEach((v) => {
					v.gong = Number(v.gong)
				})
				if(this.formData.delivery_minus_data){
					this.formData.delivery_minus_data = JSON.parse(this.formData.delivery_minus_data)
				}
				this.formData.starting_price = Number(this.formData.starting_price) / 100;
				this.formData.starting_price = this.formData.starting_price.toFixed(2);
				this.activestep = 2
			}
			this.AddSpecAuth()
		},
		mounted() {
			// 初始化 COS SDK
			this.initCOS();
		},
		methods: {
			initCOS() {
				this.beg.request({
					url: '/admin/Cos/refreshToken',
					method: 'get',
				}).then(res => {
					// 获取临时密钥
					const {
						tmpSecretId,
						tmpSecretKey,
						sessionToken,
						startTime,
						expiredTime
					} = res.data;
					this.cos = new COS({
						getAuthorization: (options, callback) => {
							callback({
								TmpSecretId: tmpSecretId,
								TmpSecretKey: tmpSecretKey,
								SecurityToken: sessionToken,
								StartTime: startTime,
								ExpiredTime: expiredTime,
							});
						},
					});
				}).catch(error => {});
			},
			getTimeFromISOString(isoString) {
				const timeMatch = isoString.match(/^(?:\d{4}-\d{2}-\d{2}T)?(\d{2}:\d{2}:\d{2}).*/);
				return timeMatch ? timeMatch[1] : '00:00:00';
			},
			openPicker() {
				this.show = true
			},
			// 营业状态
			statusChange(e) {
				this.formData.dy_status = e.detail.value
			},
			// 接单状态
			placeChange(e) {
				this.formData.place_status = e.detail.value
			},
			// 门店分类
			chainChange(e) {
				this.formData.is_chain = e.detail.value
			},
			addManitem() {
				if (this.formData.delivery_minus_data[this.formData.delivery_minus_data.length - 1].distance >= this
					.formData.delivery_scope) {
					return;
				}
				this.formData.delivery_minus_data.push({
					distance: 0,
					fee: 0,
				})
			},
			removeManitem(index) {
				this.formData.delivery_minus_data.splice(index, 1);
			},
			changeClick(value, value2, value3, value4) {
				this.province = value;
				this.city = value2;
				this.area = value3;
				this.areaCode = value4;
			},
			onhideShow() {
				this.show = false
			},
			//选中省市区
			onsetCity(e) {
				let data = e.detail.target.dataset;
				let address = data.province + data.city + data.area;
				this.formData.province = data.province
				this.formData.city = data.city
				this.formData.county = data.area
				this.show = false
				this.addressData.address = address
			},
			// 商品分类
			groupChange(n) {
				this.formData.type = n
			},
			// 营业时间
			timeChoose1(value) {
				const hsj = value.value
				const today = new Date();
				let year = today.getFullYear();
				let month = (today.getMonth() + 1).toString().padStart(2, '0');
				let day = today.getDate().toString().padStart(2, '0');
				this.formData.open_time[0][0] = `${year}-${month}-${day} ${hsj}`
			},
			timeChoose2(value) {
				const hsj = value.value
				const today = new Date();
				let year = today.getFullYear();
				let month = (today.getMonth() + 1).toString().padStart(2, '0');
				let day = today.getDate().toString().padStart(2, '0');
				this.formData.open_time[0][1] = `${year}-${month}-${day} ${hsj}`
			},
			timeChoose3(value) {
				const hsj = value.value
				const today = new Date();
				let year = today.getFullYear();
				let month = (today.getMonth() + 1).toString().padStart(2, '0');
				let day = today.getDate().toString().padStart(2, '0');
				this.formData.open_time[1][0] = `${year}-${month}-${day} ${hsj}`
			},
			timeChoose4(value) {
				const hsj = value.value
				const today = new Date();
				let year = today.getFullYear();
				let month = (today.getMonth() + 1).toString().padStart(2, '0');
				let day = today.getDate().toString().padStart(2, '0');
				this.formData.open_time[1][1] = `${year}-${month}-${day} ${hsj}`
			},
			closeTime() {
				this.timeShow = false
			},
			closeTime2() {
				this.timeShow2 = false
			},
			closeTime3() {
				this.timeShow3 = false
			},
			closeTime4() {
				this.timeShow4 = false
			},
			// 预约时长
			valChange(e) {
				this.formData.appointment_duration = e.value
			},
			// 时间段细分
			groupChangeTime(n) {
				this.formData.time_period_segmentation = n.detail.value
			},
			// 最长预约
			longestChange(e) {
				this.formData.delivery_scope = e.value
			},
			// 按钮增加
			additem(i) {
				this.formData.distance_price.push({
					gong: 0,
					duo: 0,
					price: 0,
				})
			},
			// 按钮减少
			deleteitem(i) {
				if (this.formData.distance_price.length == 1) {
					return
				}
				this.formData.distance_price.splice(i, 1)
			},
			// 营业日期
			checkboxClick(e) {
				this.formData.open_date = e.detail.value
			},
			/**
			 * 生成全球唯一标识
			 * @returns uuid
			 */
			uuid() {
				let uuid = ''
				for (let i = 1; i <= 36; i++) {
					if (i === 9 || i === 14 || i === 19 || i === 24) {
						uuid += '-'
					} else if (i === 15) {
						uuid += 4
					} else if (i === 20) {
						uuid += this.hexList[(Math.random() * 4) | 8]
					} else {
						uuid += this.hexList[(Math.random() * 16) | 0]
					}
				}
				return uuid
			},
			//logo图片
			deletePic(event) {
				if (event.name == '1') {
					this.formData.logo_img.splice(event.index, 1)
				} else if (event.name == '2') {
					this.formData.store_img.splice(event.index, 1)
				} else if (event.name == '3') {
					this.formData.qualifications.splice(event.index, 1)
				} else if (event.name == '4') {
					this.formData.business_license.splice(event.index, 1)
				}
			},
			async afterRead(event) {
				let lists = [].concat(event.file)
				if (event.name == '1') {
					let fileListLen = this.formData.logo_img.length
					lists.map((item) => {
						this.formData.logo_img.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.logo_img[fileListLen]
						this.formData.logo_img.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				} else if (event.name == '2') {
					let fileListLen = this.formData.store_img.length
					lists.map((item) => {
						this.formData.store_img.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.store_img[fileListLen]
						this.formData.store_img.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				} else if (event.name == '3') {
					let fileListLen = this.formData.qualifications.length
					lists.map((item) => {
						this.formData.qualifications.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.qualifications[fileListLen]
						this.formData.qualifications.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				} else {
					let fileListLen = this.formData.business_license.length
					lists.map((item) => {
						this.formData.business_license.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.business_license[fileListLen]
						this.formData.business_license.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				}
			},
			handleFileInUploading(event) {
				return new Promise((resolve, reject) => {
					const that = this
					const filePath = event.url
					const str = filePath.substr(filePath.lastIndexOf('/') + 1)
					const sha1Hash = CryptoJS.SHA1(str).toString();
					const fileName = '/storage/default/' + this.getCurrentDate() + '/' + str
					that.cos.uploadFile({
						Bucket: 'douyin-1325951894',
						Region: 'ap-beijing',
						Key: fileName,
						FilePath: filePath,
						SliceSize: 1024 * 1024 * 5,
						onFileFinish: function(err, data, options) {
							const fileUrl = '/' + options.Key
							that.beg.request({
								url: '/admin/Cos/callback',
								method: 'POST',
								data: {
									url: fileUrl,
									name: fileName,
									size: event.size,
									type: event.type,
									sha1: sha1Hash,
								},
							}).then(res => {
								if (res.code == 1) {
									setTimeout(() => {
										resolve(data)
									}, 500)
								}
							})
						},
					}, function(err, data, options) {});
				})
			},
			getCurrentDate() {
				const now = new Date();
				const year = now.getFullYear();
				const month = (now.getMonth() + 1).toString().padStart(2, '0');
				const day = now.getDate().toString().padStart(2, '0');
				return year.toString() + month + day;
			},
			formatHHDate(time) {
				let dt = new Date(time)
				let hour = dt.getHours().toString().padStart(2, '0')
				return `${hour}`
			},
			submit() {
				if (this.editorsave == 1) {
					if (this.formData.store_name == '') {
						uni.$u.toast('请填写门店名称')
						return
					}
					if (this.formData.dy_poi_id == '') {
						uni.$u.toast('请填写POIid')
						return
					}
					if (this.formData.phone == '') {
						uni.$u.toast('请填写手机号')
						return
					}
					if (this.formData.address == '') {
						uni.$u.toast('请填写详细地址')
						return
					}
					if (this.formData.lat < 3.15 || this.formData.lat > 53.33) {
						ElMessage.error('请检查经纬度')
						return
					}
					if (this.formData.lng < 73.33 || this.formData.lng > 135.05) {
						ElMessage.error('请检查经纬度')
						return
					}
					if (this.formData.province == '') {
						uni.$u.toast('请选择地区')
						return
					}
					if (this.formData.is_chain == 0) {
						if (this.formData.qualifications.length < 1) {
							uni.$u.toast('请上传资质图片')
							return
						}
						if (this.formData.business_license.length < 1) {
							uni.$u.toast('请上传食品经营许可证')
							return
						}
					}
					const logoSrcs3 = [];
					this.formData.qualifications.forEach((item) => {
						const exists = item.src.includes('douyin');
						if (exists) {
							const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
							logoSrcs3.push(afterCom)
						} else {
							logoSrcs3.push(item.src);
						}
					});
					this.formData.qualifications = logoSrcs3;
					const logoSrcs4 = [];
					this.formData.business_license.forEach((item) => {
						const exists = item.src.includes('douyin');
						if (exists) {
							const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
							logoSrcs4.push(afterCom)
						} else {
							logoSrcs4.push(item.src);
						}
					});
					this.formData.business_license = logoSrcs4;
					this.formData.store_img = []
					this.formData.logo_img = []

					const singleStoreItem = this.is_chain.find(item => item.value === 0);
					console.log(singleStoreItem.disable);
					if (singleStoreItem.disable) {
						this.formData.is_chain = 1
					}
					this.beg.request({
						url: '/admin/store.Store/edit',
						method: 'POST',
						data: this.formData
					}).then(res => {
						if (res.code == 1) {
							uni.showToast({
								title: "编辑成功",
								icon: "success"
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000);
						} else {
							uni.showToast({
								title: "编辑失败",
								icon: "error"
							})
						}
					})
				} else if (this.editorsave == 2) {
					if (this.formData.store_name == '') {
						uni.$u.toast('请填写门店名称')
						return
					}
					if (this.formData.dy_poi_id == '') {
						uni.$u.toast('请填写POIid')
						return
					}
					if (this.formData.phone == '') {
						uni.$u.toast('请填写手机号')
						return
					}
					if (this.formData.address == '') {
						uni.$u.toast('请填写具体地址')
						return
					}
					if (this.formData.lat < 3.15 || this.formData.lat > 53.33) {
						ElMessage.error('请检查经纬度')
						return
					}
					if (this.formData.lng < 73.33 || this.formData.lng > 135.05) {
						ElMessage.error('请检查经纬度')
						return
					}
					if (this.formData.province == '') {
						uni.$u.toast('请选择地区')
						return
					}
					if (this.formData.is_chain == 0) {
						if (this.formData.qualifications.length < 1) {
							uni.$u.toast('请上传资质图片')
							return
						}
						if (this.formData.business_license.length < 1) {
							uni.$u.toast('请上传食品经营许可证')
							return
						}
					}
					const logoSrcs3 = [];
					this.formData.qualifications.forEach((item) => {
						const exists = item.src.includes('douyin');
						if (exists) {
							const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
							logoSrcs3.push(afterCom)
						} else {
							logoSrcs3.push(item.src);
						}
					});
					this.formData.qualifications = logoSrcs3;
					const logoSrcs4 = [];
					this.formData.business_license.forEach((item) => {
						const exists = item.src.includes('douyin');
						if (exists) {
							const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
							logoSrcs4.push(afterCom)
						} else {
							logoSrcs4.push(item.src);
						}
					});
					this.formData.business_license = logoSrcs4;
					this.formData.store_img = []
					this.formData.logo_img = []
					const singleStoreItem = this.is_chain.find(item => item.value === 0);
					if (singleStoreItem.disable) {
						this.formData.is_chain = 1
					}
					this.beg.request({
						url: '/admin/store.Store/add',
						method: 'POST',
						data: this.formData
					}).then(res => {
						if (res.code == 1) {
							uni.showToast({
								title: "保存成功",
								icon: "success"
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000);
						} else {
							uni.showToast({
								title: "保存失败",
								icon: "error"
							})
						}
					})
				} else {
					if (this.formData.open_time[0].length < 2) {
						uni.$u.toast('请填写营业时间')
						return
					}
					if (this.formData.open_date.length < 1) {
						uni.$u.toast('请选择营业日期')
						return
					}
					// 判断时间大小排序
					if (this.formData.open_time[0] != null && this.formData.open_time[1] != null) {
						if (Number(this.formatHHDate(this.formData.open_time[0][0])) > Number(this.formatHHDate(this
								.formData
								.open_time[
									1][0]))) {
							let arrtime = [
								[],
								[]
							];
							arrtime[0] = this.formData.open_time[1];
							arrtime[1] = this.formData.open_time[0];
							this.formData.open_time = arrtime;
						}
					}
					if (this.formData.open_time[0].length == 0) {
						if (this.formData.open_time[1].length != 0) {
							this.formData.open_time[0] = this.formData.open_time[1];
							this.formData.open_time[1] = [];
						}
					}
					//判断时间
					if (this.formData.open_time[0][0] == 'NaN-NaN-NaN NaN:NaN:NaN') {
						uni.$u.toast('请正确填写营业时间')
						return;
					}
					this.formData.starting_price = Number(this.formData.starting_price) * 100;
					this.beg.request({
						url: '/admin/store.Store/edit',
						method: 'POST',
						data: this.formData
					}).then(res => {
						if (res.code == 1) {
							uni.showToast({
								title: "编辑成功",
								icon: "success"
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000);
						} else {
							uni.showToast({
								title: "编辑失败",
								icon: "error"
							})
						}
					})
				}
			},
			cancel() {
				uni.navigateBack({
					delta: 1
				})
			},
			getMapAddress() {
				wx.chooseLocation({
					success: (res) => {
						this.formData.douObj.address = res.address
						this.formData.douObj.longitude = res.longitude
						this.formData.douObj.latitude = res.latitude
						this.formData.address = res.address
						this.formData.lng = res.longitude
						this.formData.lat = res.latitude
					}
				});
			},
			linkWay() {
				this.linkShow = true
			},
			next(index) {
				if (index == 1) {
					this.$refs.POIForm.validate().then(res => {
						this.activestep = 0
					}).catch(errors => {
						uni.$u.toast('请填写必填项')
					})
				} else {
					this.activestep = 1
				}

			},
			getjinwei() {
				if (this.formData.url == '') {
					uni.$u.toast('请填写链接')
					return
				}
				let fenge = this.formData.url.split('=')
				let amap_id = fenge[fenge.length - 1]
				this.beg.request({
						url: '/admin/store.Store/get_dy_poi_id',
						method: 'post',
						data: {
							amap_id: amap_id
						}
					}).then((res) => {
						if (res.code == 1) {
							this.formData.douObj = res.data
							this.formData.store_name = res.data.poi_name
							this.formData.lng = res.data.longitude
							this.formData.lat = res.data.latitude
							this.formData.dy_poi_id = res.data.poi_id
							this.formData.poi_id = res.data.amap_id
							this.formData.address = res.data.address

							// MapContainerRef.value.lng = res.data.longitude
							// MapContainerRef.value.lat = res.data.latitude
							// MapContainerRef.value.init();
							uni.$u.toast(res.msg)
						} else {
							uni.$u.toast(res.msg)
						}
					})
					.catch()
			},
			imgPreview(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			imgPreview2(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			AddSpecAuth() {
				this.beg.request({
					url: '/admin/store.Store/storeAddSpecAuth',
					method: 'post'
				}).then(res => {
					if (res.code == 1) {
						const singleStoreItem = this.is_chain.find(item => item.value === 0);
						if (res.data.disable == 0) {
							singleStoreItem.disable = false

						} else {
							singleStoreItem.disable = true
							this.formData.is_chain = 1
						}
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		::v-deep .uni-forms-item {
			margin-bottom: 12rpx;
		}

		::v-deep .u-radio-group--row {
			justify-content: space-around;
		}

		::v-deep .uni-forms-item__content {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.text {
				color: #2979ff;
				margin: 0 10rpx 0 10rpx;
			}
		}

		.u-page__tag-item {
			margin-right: 20px;
			margin-top: 10rpx;
			display: flex;
			justify-content: space-around;
		}

		.area {
			width: 433rpx;
			height: 66rpx;
			border-radius: 8rpx;
			border: 1rpx solid #2979ff;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.footer {
			width: 95%;
			margin: 0 auto;
			display: flex;
			justify-content: space-around;
			align-items: center;

			::v-deep .u-button--square {
				width: 30%;
			}
		}

		.null {
			width: 100%;
			height: 30rpx;
		}

		::v-deep .u-number-box {
			margin-bottom: 10rpx;
		}

		::v-deep .picker-label {
			font-size: 36rpx;
		}

		.linkPopup {
			margin-top: 10rpx;
		}
	}
</style>